package leetcode.backtrace;


import java.util.*;

public class Lc90 {


    List<List<Integer>> ans;

    public List<List<Integer>> subsetsWithDup(int[] nums) {
        ans = new ArrayList<>();
        int n = nums.length;
        HashSet<Item> set = new HashSet<>();
        for (int i = 0; i < (1 << n); i++) {
            List<Integer> temp = new ArrayList<>();
            for (int j = 0; j < n; j++) {
                if (((i >> j) & 1) == 1) {
                    temp.add(nums[j]);
                }
            }
            set.add(new Item(temp));
        }
        Iterator<Item> iterator = set.iterator();
        while (iterator.hasNext()) {
            ans.add(iterator.next().list);
        }
        return ans;
    }

    public static void main(String[] args) {
        List<Integer> l1 = new ArrayList<>();
        List<Integer> l2 = new ArrayList<>();
        l1.add(1);
        l1.add(2);
        l2.add(1);
        l2.add(2);
        Item t1 = new Item(l1);
        Item t2 = new Item(l2);

        System.out.println(t1.equals(t2));

        Lc90 lc90 = new Lc90();
        System.out.println(lc90.subsetsWithDup(new int[]{1, 2, 2}));

        int x = 2, y = 1 << 1;
        System.out.println(y);
        System.out.println(x & y);

    }

}
class Item {
    List<Integer> list;

    public Item(List<Integer> list) {
        this.list = list;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Item item = (Item) o;
        return Objects.equals(list, item.list);
    }

    @Override
    public int hashCode() {
        Collections.sort(list);
        return Objects.hash(list);
    }
}